package redis.inaction.xx.configuration;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.inaction.xx.cache.UserStatusRedisCache;

@Configuration
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class BizRedisConfiguration {

    @Bean(name = "bizRedisTemplate")
    public RedisTemplate<String, byte[]> bizRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, byte[]> template = new RedisTemplate<>();
        template.setConnectionFactory(redisConnectionFactory);
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(RedisSerializer.byteArray());
        return template;
    }

    @Bean
    public UserStatusRedisCache userModelRedisCache(){
        return new UserStatusRedisCache();
    }
}
